package com.GreenIce.android.datastructure;

import java.util.ArrayList;
import java.util.Scanner;

import android.app.Activity;
import android.content.res.Resources;
import android.util.Log;

import com.GreenIce.android.GreenIceActivity;
import com.GreenIce.android.util.ResourceIdentifier;

public class GameLevel {
	public int world;
	public int level;
	public int tolTime;
	public int n, m;
	public ArrayList<Integer> sounds_resid = new ArrayList<Integer>();
	public ArrayList<Strike> strikes = new ArrayList<Strike>();

	/**
	 * 以level为参数的构造函数
	 * 
	 * @param level
	 */
	public GameLevel(int level) {
		Activity context = GreenIceActivity.getActivity();
		Resources r = context.getResources();
		int id = ResourceIdentifier.getRawID("level" + level);
		if (id == 0) Log.e("GameLevel", "id not found,level:" + level);

		Scanner sc = new Scanner(r.openRawResource(id));
		world = sc.nextInt();
		int le = sc.nextInt();
		if (le != level) {
			Log.e("GameLevel", "level dismatch");
		}
		this.level = level;

		String intro = sc.next();
		Log.i("GameLevel", "intro:" + intro);
		id = ResourceIdentifier.getRawID(intro);
		if (id == 0) Log.e("GameLevel", "id not found,sound name:" + intro);
		sounds_resid.add(id);
		
		n = sc.nextInt();
		for(int i = 0 ; i < n; i++){
			String name = sc.next();
			id = ResourceIdentifier.getRawID(name);
			if (id == 0) Log.e("GameLevel", "id not found,sound name:" + name);
			sounds_resid.add(id);
		}

		tolTime = 0;
		m = sc.nextInt();
		for(int i = 0 ; i < m; i++){
			Strike s = new Strike(sc.nextInt(),sc.nextInt(),sc.nextInt(),
					sc.nextInt(),sc.nextInt(),sc.nextInt());
			strikes.add(s);
			tolTime += s.pre_time + s.last_time;
		}
	}
}
